package src;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @author zhikang.shu
 * @date 2021/3/3
 * @desc TODO add description in here
 */
public class TestHLS {

    public static void main(String[] args) {
        String indexPath = "https://youku.cdn2-youku.com/20180710/12991_efbabf56/1000k/hls/index.m3u8";
        indexPath = "https://api.toongoggles.com/loggingmediaurlpassthrough/a.m3u8?avod=1&connection=wifi&language=en&device_id=&device_height=720&device_manufacturer=tcl&device_type=tv&device_width=1280&event_type=video_start&version=12.5&partner=tcl_roku_syndication&id=267196&platform=roku&vid=a.m3u8";
        indexPath = "https://hwmediaout.s3.eu-central-1.amazonaws.com/Disney/Trailer/WandaVision/IT_WANDAVISION_SPOT_15s.mp4";
        indexPath = "https://assets14.ign.com/videos/zencoder/2021/02/07/1920/4977da82bd8d01c62790b410803fba14-3906000-1612742172.mp4";
        String prePath = indexPath.substring(0,indexPath.lastIndexOf("/")+1);
        System.out.println(prePath);

        //下载索引文件
        String indexStr = getIndexFile(indexPath);
    }


    public static String getIndexFile(String urlpath){
        try{
            URL url = new URL(urlpath);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            System.out.println(httpURLConnection.getResponseCode());

            //下在资源
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8"));
            String content = "" ;
            String line;
            while ((line = in.readLine()) != null) {
                content += line + "\n";
            }
            in.close();
            System.out.println(content);
            return content;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
